#!/bin/sh
####  此脚本应该在command目录下执行

### 为了在任意路径执行该脚本，加入以下代码

WORK_PATH=$(pwd)
BASH_PATH=$(cd `dirname $0`; pwd)

##########################################


if [ ! -d "$BASH_PATH/../lib" -o  ! -d $BASH_PATH/../build ];then
   echo "dependent dir don\`t exist!"
   exit
fi

BIN="$BASH_PATH/prog_no_arg.bin"
BIN_NAME="$BASH_PATH/prog_no_arg"
CFLAGS="-Wall -c -fno-builtin -W -Wstrict-prototypes \
      -Wmissing-prototypes -Wsystem-headers"
LIB="$BASH_PATH/../lib/"
OBJS="$BASH_PATH/../build/string.o $BASH_PATH/../build/syscall.o \
      $BASH_PATH/../build/stdio.o $BASH_PATH/../build/assert.o"
DD_IN=$BIN
DD_OUT="$BASH_PATH/../hd50M.img" 

gcc -m32 $CFLAGS -I $LIB -o $BIN_NAME".o" $BIN_NAME".c"
ld -melf_i386 -e main $BIN_NAME".o" $OBJS -o $BIN
SEC_CNT=$(ls -l $BIN|awk '{printf("%d", ($5+511)/512)}')

if [ -f $BIN ];then
   dd if=$DD_IN of=$DD_OUT bs=512 count=$SEC_CNT seek=300 conv=notrunc
fi

